<?php
include('include/config.inc.php');
if(!isset($_SESSION['s_activId'.$cfgPack])
  || (isset($_SESSION['s_userType'.$cfgPack]) && isset($cfgFileNames['party'][$_SESSION['s_userType'.$cfgPack]]) 
      && $cfgFileNames['party'][$_SESSION['s_userType'.$cfgPack]] == 0))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{
  $count = 0;
  $productArray = array();
	/////////////////  Filter date View:Start
	if(isset($_REQUEST['fromDateYear']))
		$fromDate  = $_REQUEST['fromDateYear']."-".$_REQUEST['fromDateMonth']."-".$_REQUEST['fromDateDay'];
	else
		$fromDate  = date("Y-m-01");
	
	if(isset($_REQUEST['toDateYear']))
		$toDate    = $_REQUEST['toDateYear']."-".$_REQUEST['toDateMonth']."-".$_REQUEST['toDateDay'];
	else
		$toDate    = date("Y-m-d");
	/////////////////  Filter date View:Stop
   
  $selectProduct = "SELECT party.companyName,randrmaster.srNo,supplier.companyName,randrmaster.address,
                           DATE_FORMAT(randrmaster.complaintDate,'%d-%m-%Y')AS complaintDate,
                           DATE_FORMAT(randrmaster.targetDate,'%d-%m-%Y')AS targetDate,
                           randrmaster.rAndRMasterId
                      FROM randrmaster
                      JOIN party ON party.partyId = randrmaster.partyId
                      JOIN supplier ON supplier.supplierId = randrmaster.supplierId
                     WHERE randrmaster.complaintDate >= '".$fromDate."'
                       AND randrmaster.complaintDate <= '".$toDate."'";                    
  $selectProductRes = mysql_query($selectProduct);
  while($row = mysql_fetch_array($selectProductRes))
  {
  	$productArray[$count]['rAndRMasterId']  = $row['rAndRMasterId'];
  	$productArray[$count]['companyName']  = $row['companyName'];
  	$productArray[$count]['srNo']         = $row['srNo'];
  	$productArray[$count]['companyName']  = $row['companyName'];
  	$productArray[$count]['address']      = $row['address'];
  	$productArray[$count]['complaintDate']= $row['complaintDate'];
  	$productArray[$count]['targetDate']   = $row['targetDate'];
  	$count++;
  }
	
  include("./bottom.php");
  $smarty->assign("productArray",$productArray);
  $smarty->assign("fromDate",$fromDate);
  $smarty->assign("toDate",$toDate);
  $smarty->display("rAndRList.tpl");
}
?>